﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MayhemWpf.UserControls;

namespace ComputerMayhem.Wpf
{
    /// <summary>
    /// Interaction logic for ClockConfig.xaml
    /// </summary>
    public partial class ClockConfig : WpfConfiguration
    {
        public ClockConfig(int hour, int minute)
        {
            InitializeComponent();
            Hour = hour;
            Minute = minute;
        }

        public override string Title
        {
            get
            {
                return "Select time";
            }
        }

        public int Hour
        {
            get;
            set;
        }

        public int Minute
        {
            get;
            set;
        }

        public override void OnLoad()
        {
            HourBox.Text = Hour.ToString();
            MinuteBox.Text = Minute.ToString();
        }

        private void HourMinuteBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            CanSave = true;
            int hour;
            bool parseHour = int.TryParse(HourBox.Text, out hour);

            int minute;
            bool parseMinute = int.TryParse(MinuteBox.Text, out minute);

            if (!(parseHour && parseMinute))
            {
                CanSave = false;
            }

        }

        public override void OnSave()
        {
            int hour;
            bool parseHour = int.TryParse(HourBox.Text, out hour);

            int minute;
            bool parseMinute = int.TryParse(MinuteBox.Text, out minute);

            if (parseHour && parseMinute)
            {
                Hour = hour;
                Minute = minute;
            }
        }
    }
}
